// pages/search/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wordlist:[],
    index:0,
    // title:"题目",
    finishdat:"2021-02-09 16:07",
    whichtype:null,
    description:"描述",
    grade:null,
    typeListen:"听写",
    typeRecite:"背诵",
    keyWord:'',
    phone:""
  },
 
  toWork(e){
    var item=e.currentTarget.dataset.id;;
    var Title=this.data.wordlist[item].title;
    var id=this.data.wordlist[item].id;
    var descripte=this.data.wordlist[item].description;
    var content=this.data.wordlist[item].content;
    console.log('index:'+item)
    wx.navigateTo({
      url: '/pages/work/work?title='+Title+'&id='+id+'&description='+descripte+'&content='+content,
    })
  },
  
  search(){
    var word=this.data.keyWord;
    word=word.toString();
    console.log(word);
    var that=this; 
    var phoneNumber=wx.getStorageSync('phone');
    wx.request({
      url: 'https://www.beitingok.cn:8082/homework/searchHomework?userInfo='+phoneNumber,
      data: {
        keywords:word
      },
      method:'POST',
        success:res=>{
          console.log(res);
          var listarr=res.data.data.homeworkList;
          console.log(listarr);
          that.setData({
            wordlist:listarr,
          })
          //  console.log(that.data.wordlist)
        }
    })
  },

  writekeyword(e){
    this.setData({
    keyWord:e.detail.value
    });
   },

   
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var getPhone = wx.getStorageSync('phone');
    if(getPhone){
      this.setData ({
        phone:getPhone
      })
      console.log("同步 从本地缓存取出数据phone=" +getPhone);
    }
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})